﻿using winS.UnityEditor.Undo;

namespace winS.UnityEditor.ProcessEditor
{
    public class ConnectNodeCommand : IUndoCommand
    {
        public string info => "连接节点";

        private readonly InputPort inputPort;
        private readonly OutputPort outputPort;
        private readonly StepGraphView stepGraphView;
        private readonly Connectionline connectionLine;

        public ConnectNodeCommand(Connectionline connectionLine, StepGraphView stepGraphView)
        {
            this.stepGraphView = stepGraphView;
            this.connectionLine = connectionLine;
            inputPort = connectionLine.inputPort;
            outputPort = connectionLine.outputPort;
        }

        public void Redo()
        {
            connectionLine.Connect(inputPort, outputPort);
            stepGraphView.AddConnectionline(connectionLine);
        }
        public void Undo()
        {
            connectionLine.Disconnect();
            stepGraphView.RemoveConnectionline(connectionLine);
        }
    }
}